const getRandomHexColor = (): `#${string}` => {
  const hex = Math.floor(Math.random() * 0xffffff)
    .toString(16)
    .padStart(6, "0");
  return `#${hex}` as `#${string}`;
};

export function cluster(
  radius: number = 100,
  minSize: number = 25,
  maxSize: number = 60,
  labelsVisible: boolean = true,
  textSymbol: any = {
    type: "text",
    color: getRandomHexColor(),
    font: {
      weight: "bold",
      family: "Noto Sans",
      size: "12px",
    },
  },
  labelPlacement: string = "center-center",
  maxScale: number = 2300,
  symbol: any = {
    type: "simple-marker",
    color: getRandomHexColor(),
    style: "circle",
    outline: {
      width: 1,
      color: getRandomHexColor(),
    },
  }
) {
  return {
    type: "cluster",
    maxScale: maxScale,
    clusterRadius: radius + "px",
    clusterMinSize: minSize + "px",
    clusterMaxSize: maxSize + "px",
    labelsVisible: labelsVisible,
    symbol: symbol,
    labelingInfo: [
      {
        deconflictionStrategy: "none",
        labelExpressionInfo: {
          expression: "$feature.cluster_count",
        },
        symbol: textSymbol,
        labelPlacement: labelPlacement,
      },
    ],
  };
}
